<template>
	<view class="box-sizing overflow" style="padding: 10px; background: #fff;">
		<uni-forms  :modelValue="formData" label-position="top">
			<uni-forms-item label-width="200"  label="请输入提现金额">
				<uni-easyinput type="text" v-model="formData.withdrawalAmount" placeholder="请输入提现金额" />
				<view class="overflow">
					<view class="fl" style="color: #999; font-size: 14px; line-height: 40px;">可提现金额{{balance}}元</view>
					<view class="fr"  style="color: #ccc; font-size: 12px; line-height: 40px;">
						1-2个工作日内到账
					</view>
				</view>
			</uni-forms-item>
			<!-- v-if="type!='0'" -->
			<uni-forms-item v-if="type!='0'"  label-width="200"   label="请上传收款二维码">
				<view v-if="formData.paymentPic" style="width:140px; height: 94px; margin: auto; overflow: hidden;">
					<image style="width: 100%;" mode="widthFix" :src="formData.paymentPic" ></image>
				</view>
				
				<u-icon v-else @click="up_cart" size="80" name="camera"></u-icon>
			</uni-forms-item>
			<uni-forms-item label-width="200"  label="填写真实姓名">
				<uni-easyinput type="text" v-model="formData.payee" placeholder="请输入姓名" />
			</uni-forms-item>
			<uni-forms-item>
				<button @click="submit" style="background:#FF2E03 ; color: #fff; width: 90%; border-radius: 30px; font-size: 14px; line-height: 46px; margin-top: 8px;" type="default">立即提现</button>
			</uni-forms-item>
		</uni-forms>
		
		
		


		
		
<!-- 		<view class="box-sizing overflow" style="padding:0 10px; margin-top: 10px; background: #fff; border-radius: 12px;">
			<view class="title_line">
				选择提现方式
			</view>
			<view style="box-sizing: border-box; padding-left: 10px;">
				<radio-group @change="radioChange">
					<view style="overflow: hidden; margin-bottom: 20px;" class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in pay_list" >
					<label :key="item.value">
						
						<view class="fl">
						<view class="fl"><u-icon  size="40" :color="item.color" :name="item.src"></u-icon></view> 
						
						<view style="margin-top: 8px; margin-left: 10px;" class="fl">{{item.test}}</view> 		
						</view>
						
						
						<view class="fr" style="margin-top: 8px;">
							<radio color="#FF2E03" style="transform:scale(0.7)" :checked="index === current" :value="item.value"  />
						</view>
					</label>
					</view>
				</radio-group>
				
			</view>
		</view> -->
<!-- 		<view v-if="type!='0'" @click="bind" style="color: #333; line-height: 40px; text-align: right;">
			
			绑定支付方式
		</view> -->
		
<!-- 		<view style="margin-top: 100px;">
			
			<button @click="pay_click" style="background:#FF2E03 ; color: #fff; width: 90%; border-radius: 30px; font-size: 14px; line-height: 46px; margin-top: 8px;" type="default">立即提现</button>
		</view> -->
		
	</view>
</template>

<script>
	import {canBalanceWithdrawal,withdrawal} from '../../common/config/request.js';
	// import {baseURL} from '../../components/config.js';
	// canBalanceWithdrawal
	export default {
		data() {
			return {
				balance:uni.getStorageSync('balance'),
				formData:{
					type:0,
					withdrawalAmount:'',
					paymentPic:'',
					payee:''
				},
				type:'0',
				pay_list:[
					{
						test:'微信支付',
						src:'weixin-circle-fill',
						value:'wx',
						color:'#04BE02'
					},
					
					
					{test:'支付宝支付',
					src:'zhifubao-circle-fill',
					value:'zfb', 
					checked: 'true',
					color:'#1678ff'
					}
				],
				current:0
			}
		},
		onShow() {
			this.canBalanceWithdrawal()
		},
		methods: {
			canBalanceWithdrawal(){
				canBalanceWithdrawal().then((e)=>{
					console.log(e)
					this.type=e.data.data
				})
			},
			radioChange(){},
			bind(){
				uni.navigateTo({
					url:'/pages/distill/bind'
				})
			},
			up_cart(){
				uni.chooseImage({
				    success: (chooseImageRes) => {
				        const tempFilePaths = chooseImageRes.tempFilePaths;
				        uni.uploadFile({
				            url: baseURL+'/common/upload',
				            filePath: tempFilePaths[0],
				            name: 'file',
							header:{
								Authorization:'Bearer'+' '+uni.getStorageSync('token')
							},
				            formData: {
				                'user': 'test'
				            },
				            success: (uploadFileRes) => {
								console.log(uploadFileRes)
								// this.paymentPic=JSON.parse(uploadFileRes.data).data.fileName
								// if(e=='z'){
								// 	this.model1.userInfo.cardNoImg1=JSON.parse(uploadFileRes.data).data.fileName
								// }else{
								// 	this.model1.userInfo.cardNoImg2=JSON.parse(uploadFileRes.data).data.fileName
								// }
								this.formData.paymentPic=JSON.parse(uploadFileRes.data).data.fileName
				                console.log( JSON.parse(uploadFileRes.data) );
				            }
				        });
				    }
				});
			},
			submit(){
				if(this.balance==0){
					return uni.showToast({
							  title:'可提现金额为0',
							  icon: 'none',
							  duration:1000,
							  mask: true
							})
				}
				// formData:{
				// 	type:0,
				// 	withdrawalAmount:'',
				// 	paymentPic:'',
				// 	payee:''
				// },
				if(this.formData.withdrawalAmount>this.balance){
					return uni.showToast({
							  title:'提现金额不能大于余额',
							  icon: 'none',
							  duration:1000,
							  mask: true
							})
				}
				if(this.formData.payee==''){
					return uni.showToast({
							  title:'请输入姓名',
							  icon: 'none',
							  duration:1000,
							  mask: true
							})
				}
				if(this.formData.paymentPic==''){
					return uni.showToast({
							  title:'请上传收款码',
							  icon: 'none',
							  duration:1000,
							  mask: true
							})
				}
				
				
				withdrawal(this.formData).then((e)=>{
					return uni.showToast({
							  title:e.data.msg,
							  icon: 'none',
							  duration:1000,
							  mask: true
							})
				})
				console.log(this.formData)
			},
		}
	}
</script>

<style>
.title_line{font-size: 18px; line-height: 50px; font-weight: bold;}
</style>
